package com.matrix.geo.playmysqlgeo.serializers;

import com.fasterxml.jackson.core.JacksonException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.matrix.geo.playmysqlgeo.util.JtsUtil;
import org.locationtech.jts.geom.MultiPolygon;
import org.locationtech.jts.geom.Polygon;

import java.io.IOException;

public class PolygonJacksonDeserializer extends JsonDeserializer<Polygon> {
    @Override
    public Polygon deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JacksonException {
        return ((Polygon) JtsUtil.geoJson2Geometry(jsonParser.getCodec().readTree(jsonParser).toString()));
    }
}
